<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>修改密码</title>
    <link rel="stylesheet" href="css/conmmon.css">
    <link rel="stylesheet" href="css/login.css">
    <script src="js/jquery.min.js"></script>
    <script src="js/common.js"></script>
</head>
<body>
<!-- 导航栏 -->
<div class="nav">
    <img src="img/logo2.jpg" alt="">
    <a class="title" href="myblog_list.html">我的博客系统</a>
    <!-- 用来占据中间位置 -->
    <span class="spacer"></span>
    <a href="blog_list.html">主页</a>
    <a href="reg.html">注册</a>
    <!-- <a href="#">注销</a> -->
</div>
<!-- 版心 -->
<div class="login-container">
    <!-- 中间的登陆框 -->
    <div class="login-dialog" id="secret">
        <h3>修改密码</h3>
        <div class="row">
            <span>新密码</span>
            <input type="password" id="password" placeholder="请输入新密码">
        </div>
        <div class="row">
            <span>确认密码</span>
            <input type="password" id="passwordagainst" placeholder="请再次输入新密码">
        </div>
        <div class="row">
            <button id="submit" onclick="mysub()">提交</button>
        </div>
        <!-- <a id="forget" href="#">忘记密码</a> -->
    </div>
</div>

<script>    
        function mysub(){
            // 1.非空效验
            var uid = getUrlValue("uid");
           var password = jQuery("#password");
           var passwordagainst = jQuery("#passwordagainst");
           if(password.val()==""){
            alert("请先输入密码！");
            password.focus();
            return;
           }
           if(passwordagainst.val()==""){
            alert("请先输入确认密码！");
            passwordagainst.focus();
            return;
           }
            // 2.判断两次密码是否一致
          if(password.val()!=passwordagainst.val()){
            alert("两次密码输入的不一致，请先检查！");
            password.focus();
            return;
           }
           if(confirm("是否要修改密码")){
                // 3.ajax 提交请求 
                jQuery.ajax({
                    url:"/user/updatesecret",
                    type:"POST",
                    data:{"uid":uid,"password":password.val()},
                    success:function(result){
                        // 响应的结果
                        if(result != null && result.code == 200 && result.data == 1){
                            // 执行成功
                            if(confirm("恭喜：密码修改成功！是否要跳转到登录页面？")){
                                location.href = "/login.html";
                            }
                        }else{
                            alert(result.msg);
                        }
                    }
                });
           }
        }

    </script>
</body>

</html>
